<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">代理商管理</a></li>
        <li class="active">费率管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="selectForm" class="form-inline" th:action="@{/tradeType/list}" role="form">
            <div class="form-group">
                <div class="form-group">
                    <label class="control-label">商户号：</label>
                    <div class="control-inline">
                        <input type="text" name="mch_id" class="form-control" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">类型名称：</label>
                    <div class="control-inline">
                        <input type="text" name="tradeType" class="form-control" />
                    </div>
                </div>

                <shiro:hasPermission name="tradeType:list">
                    <div class="btn-group btn-group-sm" style="text-align:left;">
                        <button type="button" id="btn_query" class="btn btn-info">查询</button>
                        <button type="reset" id="btn_reset" class="btn btn-warning">重置</button>
                    </div>
                </shiro:hasPermission>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="toolbar btn-group">
            <shiro:hasPermission name="product:batchDelete">
                <button id="btn_batch_delete" type="button" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
                </button>
            </shiro:hasPermission>
        </div>


        <div class="wrapper-content">
            <div class="ibox-content animated fadeInRight">
                <div class="jqGrid_wrapper">
                    <table id="table_list"></table>
                    <div id="pager_list"></div>
                </div>
            </div>
        </div>

    </div>
</section>

<!-- 支付产品详情模态框 -->
<div id="tradeTypeDetailModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">代理商费率信息</h4>
            </div>
            <div class="modal-body">
                <div id="tradeTypeOpenWindow">
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<script type="text/javascript">
    $(document).ready(function () {

        var dataGrid = new DataGrid({

            dataGrid: $('#table_list'),
            searchForm: $('#selectForm'),
            dataGridPage: $('#pager_list'),
            multiselect: true,
            multiboxonly: true,
            rownumbers: true,
            rownumWidth: 60,
            colModel: [
                {
                    header: '代理商名称',
                    name: 'mch_id',
                    index: 'mch_id',
                    editable: false,
                    width: 70,
                    sortable: false,
                    search: false
                },
                {
                    header: '类型名称',
                    name: 'tradeType',
                    index: 'tradeType',
                    editable: false,
                    width: 70,
                    sortable: false,
                    search: false
                },
                {
                    header: '费率',
                    name: 'rate',
                    index: 'rate',
                    editable: false,
                    width: 70,
                    sortable: false,
                    search: false
                },
                {
                    header: '上游商户号',
                    name: 'name',
                    index: 'name',
                    editable: false,
                    width: 70,
                    sortable: false,
                    search: false
                },
                {
                    header: '状态',
                    name: 'status',
                    index: 'status',
                    editable: false,
                    width: 70,
                    sortable: false,
                    search: false,
                    formatter: function (value) {
                        switch (value) {
                            case 1:
                                return '启用';
                            case 0:
                                return '禁用';
                            default:
                                return '';
                                break
                        }
                    }
                },
                {
                    header: '操作',
                    name: 'operate',
                    index: 'operate',
                    width: 80,
                    align: 'center',
                    sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        var edit = '<a class="table-btn table-btn-info" href="javascript:void(0)" onclick="edit(\'' + rowObject.mch_id + '\', \'' + rowObject.tradeType + '\')">编辑</a>' ;
                        //var del = '<a  class="table-btn table-btn-danger" href="javascript:void(0)" onclick="deleteProduct(' + rowObject.id + ')">删除</a>';
                        return edit;
                    }
                }
            ]
        });

        //加载表格
        $("#btn_query").click(function () {
            $("#table_list").jqGrid('setGridParam', {
                datatype: 'json',
                postData: {
                    mch_id: $('input[name=mch_id]').val(),
                    tradeType: $('input[name=tradeType]').val()
                }, // 发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });

        var productIdStr;//批量
        //批量删除
        // $("#btn_batch_delete").click(function(){
        //     var checkedRows= Core.selectJqMutiData("#table_list");
        //     if(checkedRows!=false){
        //         Core.confirm("确定删除选中的"+checkedRows.length+"条记录？",function () {
        //             productIdStr="";
        //             $.each(checkedRows, function (i, item) {
        //                 var rowData = $("#table_list").jqGrid('getRowData', checkedRows[i]);
        //                 productIdStr+=(rowData.id+",");
        //             });
        //             productIdStr=productIdStr.substring(0,productIdStr.length-1);
        //             Core.postAjax(ctxPath + "/product/batch/delete",{"productIdStr":productIdStr},function(data){
        //                 if(data.code==200){
        //                     Core.refreshJqTable("#table_list");
        //                 }
        //                 layer.msg(data.msg);
        //             },"get")
        //         })
        //     }
        // });

    });

    /*删除*/
    // function deleteProduct(productId) {
    //     Core.confirm("确定删除该支付产品？",function () {
    //         Core.postAjax(ctxPath + "/product/delete", {"productId": productId}, function (data) {
    //             if (data.code == 200) {
    //                 Core.refreshJqTable("#table_list");
    //             }
    //             layer.msg(data.msg);
    //         }, "get")
    //     })
    // }

    /*编辑*/
    function edit(mchId, tradeType) {
        Core.load("#tradeTypeOpenWindow", ctxPath + "/tradeType/edit?tradeType=" + tradeType + "&mchId=" + mchId, function () {
            $("#tradeTypeDetailModal").modal("show");
        }, 2);
    }

</script>
